﻿using System;
using System.Collections.Generic;
using System.Linq;
using CommonDomain.Persistence;
using Machine.Specifications;
using Machine.Specifications.Runner.Impl;
using Sponsorship.Domain;
using Sponsorship.Infrastructure.BootStrapping.Registries;
using StructureMap;

namespace Sponsorship.Specs.Commands
{
    public class when_a_command_is_sent
    {
        static IEnumerable<Type> _commandList;

        Establish context = () =>
                                {
                                    _commandList = typeof(ICommand).Assembly.GetTypes().Where(x => x.GetInterface(typeof(ICommand).Name) != null);
                                    ObjectFactory.Initialize(x =>
                                                                 {
                                                                     x.AddRegistry(new CommandHandlerRegistry());
                                                                     x.For<IRepository>().Use(new FakeRepository());
                                                                 });
                                };

        It should_have_a_commandhandler = () => _commandList.ForEach(x => ObjectFactory.GetInstance(typeof(ICommandHandler<>).MakeGenericType(x)));
    }
}